package com.x.service.transactional;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.x.dao.LocationDAO;
import com.x.dao.ProjectDAO;
import com.x.model.Location;
import com.x.model.Project;

@Component("projectService")
public class ProjectService {

	@Autowired
	private ProjectDAO projectDAO;
	@Autowired
	private LocationDAO locationDAO;

	public void save(String name, String description) {
		Project project = new Project();
		project.setName(name);
		project.setDescription(description);
		// project.setCreatetime(new Timestamp(System.currentTimeMillis()));
		projectDAO.saveProject(project);
	}

	public void update(Project project) {
		projectDAO.saveProject(project);

	}

	public String count() {
		return projectDAO.count();
	}

	public String findNum(String sql) {
		return projectDAO.findNum(sql);
	}

	public Map<String, Object> list(int startIndex, int length,
			List<String[]> wherePart, List<String[]> odrerPart) {

		return projectDAO.list(startIndex, length, wherePart, odrerPart);
	}

	public boolean create(String name, String description, String type,String district) {
		if(projectDAO.notExist(name,type,district)){
			Location location = locationDAO.getNodeById(district);
			projectDAO.create(name,type,description,location);
			return true;
		}
		return false;
	}

	public void delete(String id) {
		projectDAO.delete(id);		
	}
}
